package com.mentalsurvey.controller;

import com.mentalsurvey.entity.Option;
import com.mentalsurvey.service.OptionService;
import com.mentalsurvey.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/options")
public class OptionController {
    @Autowired
    private OptionService optionService;

    /**
     * 批量添加选项接口
     * POST /api/options/batch
     */
    @PostMapping("/batch")
    public Result<?> addOptionsBatch(@RequestBody List<Option> options) {
        if (options == null || options.isEmpty()) {
            return Result.error("选项列表不能为空");
        }

        for (Option option : options) {
            if (option.getPaperCode() == null || option.getOptionText() == null || option.getScore() == null) {
                return Result.error("每个选项必须包含 paperCode、optionText 和 score");
            }
        }

        int insertedCount = optionService.addOptionsBatch(options);
        if (insertedCount > 0) {
            return Result.success("成功添加 " + insertedCount + " 条选项", null);
        } else {
            return Result.error("添加失败");
        }
    }
}
